package filters;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

import com.google.common.io.Files;

/**
 * Demonstration of Pipes and Filters Pattern: Pipe.<p>
 * 
 * Use two Filters: 
 * 
 * <ol>
 * <li>NamesFilter
 * <li>DuplicatesFilter
 * </ol>
 * 
 * Demonstrates pipe, each filter output used inline.<p>
 * 
 * Each filter applies filtration, reducing input. Probable names are 
 * 	filtered. Apache OpenNLP imperfect.  Improve results further by removing 
 * 	duplicate first, last name fields: "Kevin, Kevin".<p>
 *
 */

public class Pipe
{

	public static void main( String[] args ) throws IOException
	{

		String testText = Files.readLines(new File(args[0]), 
				Charset.forName("UTF8")).toString();
		
		NamesFilter names = 
				new NamesFilter(testText.split("\\s"),"person");
		
		System.out.println( "Names found:" );
		
		System.out.println( names._found );
		
		System.out.println( "After removing duplicated first, last names:" );

		UniqueFilter unique = new UniqueFilter( 
				names._found.toArray(new String[]{}) );
		
		System.out.println( unique._found );
		
		
	}//method
	

}//class
